$(function (){
	function addPaginat(){
		var swipeSpan= '<span class="swipe-paginat-switch current"></span>';
		var swipeItem = $("#mySwipe .swipe-item");
		for(var i = 1;i< swipeItem.length;i++){
			swipeSpan += '<span class="swipe-paginat-switch"></span>';
		}
		$(".swipe-paginat").html(swipeSpan);
	}
	function mySwipe(){
		// pure JS
		var elem = $("#mySwipe")[0];
		window.mySwipe = Swipe(elem, {
		  auto: 3000,
		  continuous: true,
		  disableScroll: true,
		  stopPropagation: true,
		  callback: function(index, element) {
		  	var paginat = $(".swipe-paginat-switch");
		  	paginat.eq(index).addClass("current").siblings().removeClass("current");
		  }
		});
	}

    //添加品牌
    $.ajax({
        url:ApiUrl+"/index.php?act=shop",
        type:'get',
        dataType:'json',
        success:function(result){
            var rData =  result.datas;
            rData.WapSiteUrl = WapSiteUrl;
            rData.upload_site_url = upload_site_url;
            var html = template.render('home_body',rData);
            $("#home-cnt-wp").html(html);

            addPaginat();
            mySwipe();

            $('.home1').click(function(){
                var keyword = encodeURIComponent($(this).attr('keyword'));
                location.href = WapSiteUrl+'/tmpl/product_list.html?keyword='+keyword;
            });

            $('.home2').click(function(){
                var keyword = encodeURIComponent($(this).attr('keyword'));
                location.href = WapSiteUrl+'/tmpl/product_list.html?keyword='+keyword;
            });
        }
    });
    //获取推荐商品http://192.168.1.189/index.php?act=search&op=get_booth_goods&cate_id=1074&ajax=1
	
	$('.search-btn').click(function(){
		var keyword = encodeURIComponent($('#keyword').val());
		location.href = WapSiteUrl+'/tmpl/product_list.html?keyword='+keyword;
	});
});
function writeObj(obj){ 
    var description = ""; 
    for(var i in obj){   
        var property=obj[i];   
        description+=i+" = "+property+"\n";  
    }   
    alert(description); 
}